package test;

import org.xmap.ui.View;
import org.xmap.ui.ViewManager;
import org.xmap.ui.base.Window;
import org.xmap.ui.control.PointerKeyboard;
import org.xmap.ui.views.TextAreaView;

public class KeyboardView extends TextAreaView {

    private PointerKeyboard pkb;

    public KeyboardView(View back) {
        super(back);
//        this.setBgColor(0x00ffff88);
        this.setTitleText("触笔键盘控件演示");
        this.addText("这是个触笔键盘控件演示，触笔点击数字来进行输入，选择“边框模式”子菜单可以显示或隐藏边框，选择“背景模式”子菜单可以设置背景为透明或可见。");
        this.pkb = new PointerKeyboard(this, 0, this.getClientRect().height,
                this.getClientRect().width, 30, Window.ORIENT_LEFT_DOWN);
        this.addControls(pkb);
        this.addLeftMenu("边框模式", new String[]{"边框显示", "边框隐藏"});
        this.addLeftMenu("背景模式", new String[]{"背景透明", "背景可见"});
        this.setRightMenu("返回");
    }
//    public void timeInterrupted() {
//        this.pkb.setLineColor((int) System.currentTimeMillis());
//        this.pkb.setTextColor((int) System.currentTimeMillis() + 0xffff0000);
//    }

    public void commandEvent(String command, Window sender) {
        if (command.equals("边框显示")) {
            this.pkb.setDrawRect(true);
        } else if (command.equals("边框隐藏")) {
            this.pkb.setDrawRect(false);
        } else if (command.equals("背景透明")) {
            this.pkb.setTransparent(true);
        } else if (command.equals("背景可见")) {
            this.pkb.setTransparent(false);
        } else if (command.equals("返回")) {
            ViewManager.instance.setView(this.back, View.ANIMATION_LEFT_TO_RIGHT);
        }
    }

    public boolean keyEvent(boolean flag, int keyCode, int gameAction) {
        if (flag) {
            this.setTitleText("触笔输入:" + (keyCode - 48));
        }
        return true;
    }
}
